package com.augmentum.login.model;

import com.augmentum.login.Constants;
import com.augmentum.login.util.Prop;

public class Page {

    private int totalCount;
    private int currentPage;
    private int pageCount;
    private int offSet;
    private int pageSize = Integer.parseInt(Prop.get(Constants.PAGE_SIEZ));

    public Page(int currentPage) {
        this.currentPage = currentPage;
    }

    public Page() {

    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public boolean isFirstPage() {
        return currentPage <= 1 ? true : false;
    }

    public boolean isLastPage() {
        return currentPage >= pageCount ? true : false;
    }

    public int getOffSet() {
        offSet = (currentPage - 1) * pageSize;
        return offSet;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getCurrentPage() {
        if (currentPage < 1) {
            currentPage = 1;
        }
        return currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageCount() {
        if (totalCount < 1) {
            pageCount = 0;
            return pageCount;
        }
        pageCount = (totalCount - 1) / pageSize + 1;
        return pageCount;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("Page [totalCount=");
        builder.append(totalCount);
        builder.append(", currentPage=");
        builder.append(currentPage);
        builder.append(", pageCount=");
        builder.append(pageCount);
        builder.append(", offSet=");
        builder.append(offSet);
        builder.append(", pageSize=");
        builder.append(pageSize);
        builder.append("]");
        return builder.toString();
    }
}
